from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext.webapp import template
import os
import logging
from  MainPageController import MainPageController

class MainPage(webapp.RequestHandler):
    
    controller = MainPageController()
    # instantiate API and read in the JSON
    #TREEFILE = 'DeviceAtlas.json'
    #da = api.DaApi()
    #tree = da.getTreeFromFile(TREEFILE)
    def get(self):
      
       
        #ua = self.request.user_agent
        #props = da.getPropertiesAsTyped(tree, ua)
        mobileDevice = False
        uastring = self.request.headers.get('user_agent')
        logging.info(uastring)
        if "Mobile" in uastring:
            mobileDevice = True
        
        templateValues = {"vehicles":self.controller.Run()}
        if mobileDevice:
            path = os.path.join(os.path.dirname(__file__), 'MobileMainPage.xhtml')    
        else:
            path = os.path.join(os.path.dirname(__file__), 'MainPage.html')
            
        
        self.response.out.write(template.render(path, templateValues))

application = webapp.WSGIApplication([('/', MainPage)], debug=True)



